package com.cms.edm.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cms.edm.entity.TeacherEntity;
import com.cms.edm.service.TeacherService;
import com.cms.common.utils.PageUtils;
import com.cms.common.utils.R;



/**
 * 
 *
 * @author weixiaochun
 * @email xiaochun0121@163.com
 * @date 2022-03-15 10:48:10
 */
@RestController
@RequestMapping("edm/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    /**
     * 登录
     */
    @RequestMapping("/login")
    //@RequiresPermissions("edm:teacher:list")
    public R login(@RequestBody TeacherEntity teacher){
        TeacherEntity teacherEntity = teacherService.login(teacher);

        if(teacherEntity != null){
            return R.ok().put("teacher", teacherEntity);
        }else{
            return R.error();
        }
    }

    /**
     * 登录
     */
    @RequestMapping("/validPwd")
    //@RequiresPermissions("edm:teacher:list")
    public R validPwd(@RequestBody TeacherEntity teacher){
        TeacherEntity teacherEntity = teacherService.validPwd(teacher);

        if(teacherEntity != null){
            return R.ok().put("teacher", teacherEntity);
        }else{
            return R.error();
        }
    }

    /**
     * 列表无分页
     */
    @RequestMapping("/listNoPage")
    //@RequiresPermissions("edm:teacher:list")
    public R listNoPage(){
        List<TeacherEntity> teachers = teacherService.list();
        return R.ok().put("teachers", teachers);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("edm:teacher:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = teacherService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("edm:teacher:info")
    public R info(@PathVariable("id") Long id){
		TeacherEntity teacher = teacherService.getById(id);

        return R.ok().put("teacher", teacher);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("edm:teacher:save")
    public R save(@RequestBody TeacherEntity teacher){
        teacher.setCode(String.valueOf(System.currentTimeMillis()));
		teacherService.save(teacher);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("edm:teacher:update")
    public R update(@RequestBody TeacherEntity teacher){
		teacherService.updateById(teacher);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("edm:teacher:delete")
    public R delete(@RequestBody Long[] ids){
		teacherService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
